import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import tools.DaemonThreadFactory;

import client.Connection;
import client.ConsoleView;
import model.CommandProcessor;
import model.Model;


public class Main {

	
	public void run(){
		Model m = new Model();
		CommandProcessor cp = new CommandProcessor(m);
		ConsoleView cv = new ConsoleView(cp);

		Connection con = new Connection(m);
		m.addObserver(cv);
		
		Executor ex = Executors.newSingleThreadExecutor();
		ex.execute(cv);
		
		// Spawn daemon thread cause it should close along with the console
		Executors.newSingleThreadExecutor(new DaemonThreadFactory()).execute(con);
		
	}
	
	/**
	 * Application entry point
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args){
		new Main().run();
	}

}
